package com.igeek.yygh.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.igeek.yygh.model.cmn.Dict;
import com.igeek.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * AnalysisEventListener  监听器
 * 1.不可以加入到IOC容器中
 * 2.new创建监听器时，传入BaseMapper
 *
 * @author chemin
 * @since 2024/8/19
 */
public class MyAnalysisEventListener extends AnalysisEventListener<DictEeVo> {

    private BaseMapper<Dict> baseMapper;

    public MyAnalysisEventListener(BaseMapper<Dict> baseMapper){
        this.baseMapper = baseMapper;
    }

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //表格中的每一行数据插入到数据库中  DictEeVo -> Dict
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo , dict);
        //插入数据库
        baseMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
